<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
<!--    <meta name="viewport" content="width=device-width, initial-scale=1">-->
    <script src="vue.min.js"></script>
    <script src="jquery-3.5.1.min.js"></script>
</head>

<body>
    <div id="app">
        <button v-on:click="check()">测试</button><br/>
        <button v-on:click="findAll()">/user/user/list</button><br/>
        <br/>
        用户id：<input type="number" v-model="userId"/><br/>
        <button v-on:click="findById()">/user/user/info</button><br/>
        <button v-on:click="findUserAddress()">/user/address/findUserAddress</button><br/>
        <button v-on:click="findUserCollect()">/user/collect/findUserCollect</button><br/>
        积分：<input type="number" v-model="point"/><br/>
        <button v-on:click="addPoint()">/user/user/point/add</button><br/>
        <button v-on:click="delPoint()">/user/user/point/del</button><br/>
    </div>
</body>

<script>
    let v = new Vue({
        el: "#app",
        data: {
            userId: 1,
            point: 0
        },
        methods: {
            check() {
                console.log("按钮按下");
            },
            findAll() {
                console.log("send");

                $.ajax({
                    type: "GET",
                    url: "http://localhost:88/to_user/user/list",
                    dataType: "json",
                    success: function(data){
                        console.log("success");
                        console.log(data.page.list);
                    },
                    error: function(err){
                        console.log("err");
                    }
                });
            },
            findById() {
                console.log("send");

                $.ajax({
                    type: "POST",
                    url: "http://localhost:88/to_user/user/info",
                    data: {userId: `${this.userId}`},
                    // url: "http://localhost:88/to_user/user/save",
                    // data: '{"userId": 5, "userName": "ttt", "password": "123", "phoneNumber": "123", "points": 1, "userType": 1}',
                    // contentType: "application/json",
                    dataType: "json",
                    success: function(data){
                        console.log("success");
                        console.log(data.user);
                    },
                    error: function(err){
                        console.log("err");
                    }
                });
            },
            findUserAddress() {
                console.log("send");

                $.ajax({
                    type: "POST",
                    url: "http://localhost:88/to_user/address/findUserAddress",
                    data: {userId: `${this.userId}`},
                    dataType: "json",
                    success: function(data){
                        console.log("success");
                        console.log(data.address);
                    },
                    error: function(err){
                        console.log("err");
                    }
                });
            },
            findUserCollect() {
                console.log("send");

                $.ajax({
                    type: "POST",
                    url: "http://localhost:88/to_user/collect/findUserCollect",
                    data: {userId: `${this.userId}`},
                    dataType: "json",
                    success: function(data){
                        console.log("success");
                        console.log(data.collect);
                    },
                    error: function(err){
                        console.log("err");
                    }
                });
            },
            addPoint() {
                console.log("send");

                $.ajax({
                    type: "POST",
                    url: "http://localhost:88/to_user/user/point/add",
                    data: {userId: `${this.userId}`, point: `${this.point}`},
                    dataType: "json",
                    success: function(data){
                        console.log("success");
                        console.log("current: " + data.point);
                    },
                    error: function(err){
                        console.log("err");
                    }
                });
            },
            delPoint() {
                console.log("send");

                $.ajax({
                    type: "POST",
                    url: "http://localhost:88/to_user/user/point/del",
                    data: {userId: `${this.userId}`, point: `${this.point}`},
                    dataType: "json",
                    success: function(data){
                        console.log("success");
                        console.log("current: " + data.point);
                    },
                    error: function(err){
                        console.log("err");
                    }
                });
            }
        }
    });
</script>

</html>